/*
    Trap, Shake, Kill 'Em - a multi touch, multi sensor game where the
    idea is to use two thumbs to traps enemies.
    Once trapped, shake the device for a kill! Watch out for the friendly
    flying saucers though...

    Copyright (C) 2011 Miika Ahdesmaki
    email: miika.ahdesmaki@ovi.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include "mygraphicsscene.h"
#include <QtDebug>
/*
#include <QFile>
#include <QTextStream>
#include <QStringList>

void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        switch (type) {
        case QtDebugMsg:
                txt = QString("Debug: %1").arg(msg);
                break;

        case QtWarningMsg:
                txt = QString("Warning: %1").arg(msg);
        break;
        case QtCriticalMsg:
                txt = QString("Critical: %1").arg(msg);
        break;
        case QtFatalMsg:
                txt = QString("Fatal: %1").arg(msg);
                abort();
        }

        QFile outFile("trapskemDebugLog.txt");
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
}
*/
//! [0]
int main(int argc, char **argv)
{
    const int numLevels = 10; // number of levels
    const int EnemyCount [numLevels]    = {1,2,4,1,1,4,4,5,5,5}; // enemy counts for levels
    const int AllyCount [numLevels]     = {0,1,1,0,1,2,2,3,4,6}; // ally counts for levels
    const int TrapCount [numLevels]     = {9,7,5,4,3,5,4,5,4,3}; // trap counts for levels
    const int BigBossCount [numLevels]  = {0,0,0,1,1,0,0,0,1,2}; // trap counts for levels
    const qreal speedMultiplierPerLevel [numLevels] = {1,1.3,1.2,1.5,1.5,1.5,1.6,1.7,2,2}; // speeds of creatures for the levels
    const int timePerLevel [numLevels] = {30,20,20,20,20,20,20,20,30,25}; // time given for each level in seconds
    QStringList bGImageTable;
    bGImageTable << ":/images/Level_00.jpg" << ":/images/Level_01.jpg" <<
                    ":/images/Level_02.jpg" << ":/images/Level_03.jpg" <<
                    ":/images/Level_04.jpg" << ":/images/Level_05.jpg" <<
                    ":/images/Level_06.jpg" << ":/images/Level_07.jpg" <<
                    ":/images/Level_08.jpg" << ":/images/Level_09.jpg";

    // still to add: punish for too wide traps,

    // the following line supposedly would save some memory
    // but if used disables screen locking (i.e. not possible to lock to landscape)
    // thus: commented out
    // QCoreApplication::setAttribute(Qt::AA_S60DontConstructApplicationPanes);

    QApplication app(argc, argv);
    //Lets register our custom handler, before we start
    //qInstallMsgHandler(customMessageHandler);

    // get screen geometry
    const int screenHeight = qMin(app.desktop()->screenGeometry().height(),app.desktop()->screenGeometry().width());
    const int screenWidth  = qMax(app.desktop()->screenGeometry().height(),app.desktop()->screenGeometry().width());
    //qDebug()<< "height "<<  screenHeight << " width" << screenWidth;

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));



    myGraphicsScene scene(screenWidth, screenHeight, EnemyCount, AllyCount, BigBossCount, TrapCount, speedMultiplierPerLevel, numLevels, timePerLevel, bGImageTable);

    // this signal can be used for quitting
    QObject::connect(&scene, SIGNAL(callingQuits()), &app, SLOT(quit()));

    return app.exec();
}

